package model.operator;

import java.sql.SQLException;
import java.util.HashMap;

public class OperatorService {
	private OperatorDao operatorDao;
	public void setoperatorDao(OperatorDao operatorDao) {
		this.operatorDao = operatorDao;
	}
	//지시사항 DB에 넣기!!
	public void workOrderInsert(HashMap map) throws SQLException{
		//System.out.println("서비스에서 insert하기전...!!!");
			operatorDao.workOrderInsert(map);
			//System.out.println("서비스에서 insert하고난 다음");
			int workOrderMaxNumber=operatorDao.workOrderMaxNumber();
			map.put("workorder_no", workOrderMaxNumber);
			operatorDao.historyOrderInsert(map);
	}
	public void workOrderUpdate(HashMap map) throws SQLException{
			operatorDao.workOrderUpdate(map);
			int workOrderMaxNumber=operatorDao.workOrderMaxNumber();
			map.put("workorder_no", workOrderMaxNumber);
			operatorDao.historyOrderUpdate(map);
	}
	//통계결과 뽑아오기
	public HashMap resultStatistics() throws SQLException {
		HashMap result_map = new HashMap();
		//우선, 오늘을 기준으로 '월, 일' 받아오기
		String Month=operatorDao.fetchingMonth();
		String Days=operatorDao.fetchingDays();
		HashMap pa_map = new HashMap();
		//목표성공갯수=month_goal_number/day_goal_number
		pa_map.put("MMDD","MM");pa_map.put("monOrday",Month);pa_map.put("history_status","false");
		result_map.put("month_goal_number", operatorDao.workorderStatistics(pa_map));
		pa_map.put("MMDD","DD");pa_map.put("monOrday",Days);
		result_map.put("day_goal_number", operatorDao.workorderStatistics(pa_map));
		//목표불량갯수=month_goal_bad_number/day_goal_bad_number
		pa_map.put("MMDD","MM");pa_map.put("monOrday",Month);pa_map.put("history_status","false");
		result_map.put("month_goal_bad_number", operatorDao.workorderbadStatistics(pa_map));
		pa_map.put("MMDD","DD");pa_map.put("monOrday",Days);
		result_map.put("day_goal_bad_number", operatorDao.workorderbadStatistics(pa_map));
		//성공갯수=month_success_number/day_success_number
		pa_map.put("MMDD","MM");pa_map.put("monOrday",Month);pa_map.put("history_status","start");
		result_map.put("month_success_number", operatorDao.historyStatistics(pa_map));
		pa_map.put("MMDD","DD");pa_map.put("monOrday",Days);
		result_map.put("day_success_number", operatorDao.historyStatistics(pa_map));
		//불량갯수=month_bad_number/day_bad_number
		pa_map.put("MMDD","MM");pa_map.put("monOrday",Month);pa_map.put("history_status","stop");
		result_map.put("month_bad_number", operatorDao.historyStatistics(pa_map));
		pa_map.put("MMDD","DD");pa_map.put("monOrday",Days);
		result_map.put("day_bad_number", operatorDao.historyStatistics(pa_map));
		return result_map;
	}
}
